package com.neardrug.config;

import com.neardrug.interceptor.JwtTokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rui
 * @ClassName: WebMvcConfig
 * @create 2023-10-12 21:16
 * @description
 */
@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始进行静态资源映射...");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");

        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/user")
                .addPathPatterns("/user/logout")
                .addPathPatterns("/example")
                .addPathPatterns("/patent")
                .addPathPatterns("/test")
                .addPathPatterns("/files/api")
                //.addPathPatterns("/files/download")
                .addPathPatterns("/analysis/**")
                .addPathPatterns("/apiResult/**")
                .addPathPatterns("/form/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/reset")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/webjars/**");
    }

}
